#include "clocker.h"
#include <stdio.h>
#include <string.h>

#define log(...) do {                \
            printf(__VA_ARGS__);     \
            printf("\n");            \
        } while(0);

static int device_carry_out_numbering = 0;

int clocker_start(struct clocker_object *clk)
{
    memset(clk, 0, sizeof(struct clocker_object));
    clk->num = device_carry_out_numbering++;

    clock_gettime(CLOCK_MONOTONIC, &clk->start);
    log("----------------- clocker : num:[%d] start -----------------", clk->num);
}

int clocker_end(struct clocker_object *clk)
{
    clock_gettime(CLOCK_MONOTONIC, &clk->end);
	clk->duration = (double)(clk->end.tv_nsec - clk->start.tv_nsec)/((double) 1e9) + (double)(clk->end.tv_sec-clk->start.tv_sec);
	log("----------------- clocker : num:[%d] end   -----------------", clk->num);
    log("> clocker : num [%d] run time [%f] s ...", clk->num, clk->duration);
}
